package com.zhizhi.module.synthesizes.sys.service.impl;

import com.zhizhi.common.base.BaseServiceImpl;
import com.zhizhi.module.synthesizes.sys.entity.Message;
import com.zhizhi.module.synthesizes.sys.mapper.MessageMapper;
import com.zhizhi.module.synthesizes.sys.service.MessageService;
import com.zhizhi.util.AliSendMessageUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Future;

/**
 * <p>
 * 记录发送短信的表 服务实现类
 * </p>
 *
 * @author zhu
 * @since 2019-09-03
 */
@Service
public class MessageServiceImpl extends BaseServiceImpl<MessageMapper, Message> implements MessageService {
   @Value("${accessKeyId}")
    private String accessKeyId;

   @Value("${accessKeySecret}")
    private String accessKeySecret;
    
    /*
     * @Description: 异步调用有返回值的阿里发送短信的方法
     * @param  phone, code
     * @return java.util.concurrent.Future<java.lang.Boolean>
     * @menu /
     * @status done
     */
    @Async
    @Override
    public Future<Boolean> sendMessage(String phone, String code, String templatecode) {
        Map<String, String> param = new HashMap<>();
        param.put("code", code);
        boolean flag = AliSendMessageUtils.sendMessage(accessKeyId, accessKeySecret, phone, templatecode, "飞服", param);
        return new AsyncResult<>(flag);
    }
}